<?php

class CommentsSoapController extends Zend_Controller_Action
{
    	//change this to your WSDL URI!
    private $_WSDL_URI = "http://localhost/DetaiAndroid/public/comments-soap?wsdl";

    /**
     * Action index in soap controller
     * @author Tien Nguyen
     */
    public function indexAction() {
        $this->_helper->viewRenderer->setNoRender();
        if (isset($_GET['wsdl'])) {
            //return the WSDL
            $this->hadleWSDL();
        } else {
            //handle SOAP request
            $this->handleSOAP();
        }
    }

    /**
     * Webservice 
     * @author Tien Nguyen
     */
    private function hadleWSDL() {
        $autodiscover = new Zend_Soap_AutoDiscover();
        $autodiscover->setClass('Webservices_Comments');
        $autodiscover->handle();
    }

    /**
     * Webservice with soap
     * @author Tien Nguyen
     */
    private function handleSOAP() {
        $soap = new Zend_Soap_Server($this->_WSDL_URI);
        $soap->setClass('Webservices_Comments');
        $soap->handle();
    }

    /**
     * Action for test webservice
     * @author Tien Nguyen
     */
    public function clientAction() {
        $client = new Zend_Soap_Client($this->_WSDL_URI);
        $str = '{"content":"I just comment for this ticket","commentId":0,"eventId":1,"userId":1}';

        //Zend_Debug::dump($client->addComment("admin", "123", $str)); die;
        Zend_Debug::dump($client->removeComment('admin', '123', 4)); 
        //Zend_Debug::dump($client->addUser("Nguyen Van Tien")); die;
        //Zend_Debug::dump($client->addUser('<hipro.entities.Users><username>1233</username><password>123456</password><userId>0</userId><distance>10000</distance></hipro.entities.Users>')); die;
        //Zend_Debug::dump($client->getEvents('admin', '123456'));
       $this->_helper->viewRenderer->setNoRender();
    }
}

